package com.ceres.farm.controller;

import com.ceres.entity.Result;
import com.ceres.entity.StatusCode;
import com.ceres.farm.pojo.CustFarmlandDevice;
import com.ceres.farm.service.CustFarmlandDeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/custDevice")
public class CustDeviceController {
    //农田设备
    @Autowired
    CustFarmlandDeviceService custFarmlandDeviceService;

    //设备安装

    @PostMapping("/add")
    public Result addDevice(@RequestBody CustFarmlandDevice custFarmlandDevice){
        try {
            custFarmlandDeviceService.addDevice(custFarmlandDevice);
            return new Result(true, StatusCode.OK);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR);
        }
    }

    //设备的自动启动/停止
    @GetMapping("/autoStart")
    public Result autoStart(Integer quota,Integer device){
      Integer satus=  custFarmlandDeviceService.autoStart(quota,device);
      if(satus==0){
          return new Result(false,StatusCode.ERROR);
      }
      return new Result(true,satus);
    }

    //设备的手动开启/停止
    @GetMapping("/manualControl")
    public Result manualControl(Integer device,Integer mstage){
        try {
            custFarmlandDeviceService.manualControl(device,mstage);
            return new Result(true,StatusCode.OK);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,StatusCode.ERROR);
        }
    }
}
